package com.fy.module.sys.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fy.module.sys.entity.UserMsg;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;

/**
 * <p>
 * 用户信息表 Mapper 接口
 * </p>
 *
 * @author jiang
 * @since 2023-03-21
 */
public interface UserMapper extends BaseMapper<UserMsg> {


    //根据用户id查询用户对应的个人信息  多表联查
    @Select("select distinct sys_user.* , sys_role.role_desc ,sd.dept_name from sys_user left join sys_depart sd on sys_user.depart_id = sd.id\n" +
            "                left join sys_user_role sur on sys_user.user_id = sur.user_id left join\n" +
            "               sys_role on sur.role_id =sys_role.role_code left join\n" +
            "               sys_role_permission srp on sur.role_id = srp.role_id  where sys_user.user_id=#{userId}")
    List<UserMsg> selectAllByUserId(String userId);


    /**
     * 修改用户基本信息
     */

    @Update("update sys_user\n" +
            "set account=#{account},phone=#{phone},email=#{email},sex=#{sex}\n" +
            "where user_id=#{userId};")
    int updateUserMsg(@Param("account") String account,@Param("phone") String phone, @Param("email") String email, @Param("sex") String sex,@Param("userId") String userId);


    /**
     * 修改用户密码
     * oldPassword:旧密码
     * newPassword1:新密码
     * newPassword2:确认密码
     */
    @Update("update sys_user set password=#{newPassword1} where user_id=#{userId}")
    int updateUserPassword(@Param("userId") String userId,@Param("newPassword1") String newPassword1);
    /**
     * 根据account名查询用户对象
     */
//    UserMsg findUserMsg(String account);
}
